<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-stock-edit" th:object="${stock}">
            <input id="goodsId" name="goodsId" th:field="*{goodsId}"  type="hidden">
            <div class="form-group">	
                <label class="col-sm-3 control-label">物品编号：</label>
                <div class="col-sm-8">
                    <input id="goodsNumber" name="goodsNumber" th:field="*{goodsNumber}" class="form-control" type="text" readonly="readonly">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">物品名称：</label>
                <div class="col-sm-8">
                    <input id="goodsName" name="goodsName" th:field="*{goodsName}" class="form-control" type="text" readonly="readonly">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">调整前数量：</label>
                <div class="col-sm-8">
                    <input id="stockAmount" name="stockAmount" th:field="*{stockAmount}" class="form-control" type="text" readonly="readonly">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">调整数量：</label>
                <div class="col-sm-8">
                    <input id="adjustAmount" name="adjustAmount" class="form-control" type="text" onkeyup="countStock()">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">调整后数量：</label>
                <div class="col-sm-8">
                    <input id="afterAmount" name="afterAmount" class="form-control" type="text" readonly="readonly">
                </div>
            </div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		$("#form-stock-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			submitHandler: function(form) {
				edit();
			}
		});
		
		function edit() {
			var goodsId = $("input[name='goodsId']").val();
	    	var afterAmount = $("input[name='afterAmount']").val();
	    	$.ajax({
	    		cache : true,
	    		type : "POST",
	    		url : ctx + "store/stock/edit",
	    		data : {
	    			"goodsId":goodsId,
	    			"stockAmount": afterAmount
	    		},
	    		async : false,
	    		error : function(request) {
	    			$.modal.alertError("系统错误");
	    		},
	    		success : function(data) {
	    			$.operate.saveSuccess(data);
	    		}
	    	});
	    }
		
		function countStock(){
	    	var stockAmount = $("input[name='stockAmount']").val();
	    	var adjustAmount = $("input[name='adjustAmount']").val();
	    	var afterAmount =  document.getElementById("afterAmount");
	    	afterAmount.value = stockAmount*1+adjustAmount*1;
	    	
	    }
		
		// h所有修改，光标默认定位在第1个输入框
		var oldVal=$('input:eq(4)').val();
		$('input:eq(4)').val("").focus().val(oldVal);
	</script>
</body>
</html>
